$(function() {
    init_vue();
});

function init_vue() {
    var vue = new Vue({
        el : "#myapp",
        data : {
            startRow : 0,
            endRow : 0,
            total : 0,
            firstPage : 0,
            lastPage : 0,
            pageNum : 1,
            pageSize : 15,
            list : null,
            navigatepageNums : null,
            sum:null,
            organization_id:"",
            data_cycle:'',
            organization_names:'',
        },
        events : {
            "selectOrg": function (t) {
                this.organization_id = t.organization_ids;
                this.organization_names = t.organization_names;
            }
        },
        methods : {
            init : function() {
                close_layuiLayerLoad();
                this.initControl();
                this.getData();
            },
            initControl:function () {
                var t = this;
                $('#data_cycle').daterangepicker({
                    type: 2,
                    // drops: 'up',
                    // startDate: moment().subtract('year', 1),
                    startDate: d,
                    endDate: moment(),
                    autoApply:false,
                    autoUpdateInput:true,
                    showDropdowns : true,
                    ranges : {
                        '今日': [moment().startOf('day'), moment()],
                        '昨日': [moment().subtract('days', 1),  moment()],
                        '最近7日': [moment().subtract('days', 6), moment()],
                        '最近30日': [moment().subtract('days', 29), moment()]
                    },
                    opens : 'right', //日期选择框的弹出位置
                    separator : ' to ',
                    locale : {
                        separator:'/',
                        format : 'YYYY-MM-DD', //控件中from和to 显示的日期格式
                        applyLabel : '确定',
                        cancelLabel : '取消',
                        fromLabel : '起始时间',
                        toLabel : '结束时间',
                        customRangeLabel : '自定义',
                        daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
                        monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月',
                            '七月', '八月', '九月', '十月', '十一月', '十二月' ],
                        firstDay : 1
                    }
                }, function(start, end, label) {
                    //格式化日期显示框
                    t.data_cycle = start.format('YYYY-MM-DD') + '/' + end.format('YYYY-MM-DD');
                });
            },
            showPage : function(page) {
                // alert(page);
                this.pageNum = page;
                this.getData();
            },
            getData : function() {
                showLoad();
                var t = this;
                postMsg(root+"/organizationStatistics/tolist", {
                    page_num : t.pageNum,
                    page_size : t.pageSize,
                    organization_id:t.organization_id,
                    data_cycle:t.data_cycle,
                }, function(i) {
                    t.list = null;
                    t.list = i.data.list;
                    t.startRow = i.data.startRow;
                    t.endRow = i.data.endRow;
                    t.total = i.data.total;
                    t.firstPage = i.data.firstPage;
                    t.lastPage = i.data.lastPage;
                    t.navigatepageNums = i.data.navigatepageNums;
                    t.sum = i.sum;
                    hideLoad();
                });
            },
            openTreeOrganizationWin: function () {
                this.$broadcast('openTreeOrganizationWin');
            },
            query : function () {
                this.pageNum = 1;
                this.getData();
            },
            reset_query : function () {
                this.organization_id='';
                this.organization_names='';
                this.data_cycle=d+'/'+moment().format('YYYY-MM-DD');
                this.getData();
            },
        }
    });
    vue.init();
}